package com.project.ssm.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.project.ssm.dao.ApproFileInfoMapper;
import com.project.ssm.listener.MySpringListener;
import com.project.ssm.pojo.ApproFileInfo;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

@Controller
public class HomeController {



    @RequestMapping("/home")
    @ResponseBody
    public String home(){


        return "hello";
    }

    @RequestMapping(value = "/query",method = RequestMethod.POST)
    @ResponseBody
    public String query(@RequestBody String string,HttpServletRequest request){


        JSONObject jsonObject = JSON.parseObject(string);
        String orgCode = jsonObject.getString("orgCode");
        int id = jsonObject.getInteger("id");
        System.out.println(orgCode);
        System.out.println(id);


        SqlSession session = MySpringListener.container.getBean(orgCode,SqlSession.class);
        ApproFileInfoMapper approFileInfoMapper = session.getMapper(ApproFileInfoMapper.class);
        ApproFileInfo approFileInfo = approFileInfoMapper.selectByPrimaryKey(id);

        System.out.println(approFileInfo);

        return "hello";
    }
}
